home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / pibasy47.zip / PIBASYNC.PAS < prev    next >
Pascal/Delphi Source File  |  1988-06-03  |  11KB  |  199 lines

  1. UNIT PibAsync;
  2.  
  3. (*----------------------------------------------------------------------*)
  4. (*         PIBASYNC.PAS   --- Asynchronous I/O for Turbo Pascal         *)
  5. (*----------------------------------------------------------------------*)
  6. (*                                                                      *)
  7. (*  Author:  (c) 1985, 1986, 1987, 1988 by Philip R. Burns              *)
  8. (*                                                                      *)
  9. (*  Version: 1.0   (January, 1985)                                      *)
  10. (*           2.0   (June, 1985)                                         *)
  11. (*           2.1   (July, 1985)                                         *)
  12. (*           3.0   (October, 1985)                                      *)
  13. (*           3.1   (October, 1985)                                      *)
  14. (*           3.2   (November, 1985)                                     *)
  15. (*           4.0   (October, 1986)                                      *)
  16. (*           4.1   (December, 1986)                                     *)
  17. (*           4.2   (January, 1987)                                      *)
  18. (*           4.3   (March, 1987)                                        *)
  19. (*           4.4   (July, 1987)                                         *)
  20. (*           4.5   (November, 1987)                                     *)
  21. (*           4.6   (January, 1988)                                      *)
  22. (*           4.7   (May, 1988)                                          *)
  23. (*                                                                      *)
  24. (*  Systems: For MSDOS/PC DOS on IBM PCs and close compatibles only.    *)
  25. (*                                                                      *)
  26. (*  History: Some of these routines are based upon ones written by:     *)
  27. (*                                                                      *)
  28. (*              Alan Bishop                                             *)
  29. (*              C. J. Dunford                                           *)
  30. (*              Michael Quinlan                                         *)
  31. (*              Gene Harris                                             *)
  32. (*                                                                      *)
  33. (*           I have cleaned up these other authors' code, fixed some    *)
  34. (*           bugs, and added many new features.                         *)
  35. (*                                                                      *)
  36. (*           In particular, starting with v4.0 of PibTerm, both input   *)
  37. (*           and output to the serial port is buffered and interrupt-   *)
  38. (*           driven.  Also, XON/XOFF support has been moved to the      *)
  39. (*           serial port interrupt handler, which results in fewer      *)
  40. (*           overrun problems.                                          *)
  41. (*                                                                      *)
  42. (*           Suggestions for improvements or corrections are welcome.   *)
  43. (*                                                                      *)
  44. (*           If you use this code in your own programs, please be nice  *)
  45. (*           and give proper credit.                                    *)
  46. (*                                                                      *)
  47. (*----------------------------------------------------------------------*)
  48. (*                                                                      *)
  49. (*  Routines:                                                           *)
  50. (*                                                                      *)
  51. (*     BIOS_RS232_Init        ---    Use BIOS to initialize port        *)
  52. (*     Async_Isr              ---    Com port interrupt service routine *)
  53. (*     Async_Init             ---    Performs initialization.           *)
  54. (*     Async_Clear_Errors     ---    Clear pending serial port errors   *)
  55. (*     Async_Reset_Port       ---    Resets UART parameters for port    *)
  56. (*     Async_Open             ---    Sets up COM port                   *)
  57. (*     Async_Close            ---    Closes down COM port               *)
  58. (*     Async_Carrier_Detect   ---    Checks for modem carrier detect    *)
  59. (*     Async_Carrier_Drop     ---    Checks for modem carrier drop      *)
  60. (*     Async_Buffer_Check     ---    Checks if character in COM buffer  *)
  61. (*     Async_Term_Ready       ---    Toggles terminal ready status      *)
  62. (*     Async_Find_Delay       ---    Find busy wait count for 1ms delay *)
  63. (*     Async_Receive          ---    Reads character from COM buffer    *)
  64. (*     Async_Receive_With_Timeout                                       *)
  65. (*                            ---    Receives char. with timeout check  *)
  66. (*     Async_Ring_Detect      ---    If ringing detected                *)
  67. (*     Async_Send             ---    Transmits char over COM port       *)
  68. (*     Async_Send_String      ---    Sends string over COM port         *)
  69. (*     Async_Send_String_With_Delays                                    *)
  70. (*                            ---    Sends string with timed delays     *)
  71. (*     Async_Send_Break       ---    Sends break (attention) signal     *)
  72. (*     Async_Percentage_Used  ---    Returns percentage com buffer used *)
  73. (*     Async_Purge_Buffer     ---    Purges receive buffer              *)
  74. (*     Async_Release_Buffers  ---    Free memory for serial port queues *)
  75. (*     Async_Set_Rejection    ---    Set noise rejection processing     *)
  76. (*     Async_Setup_Port       ---    Define port base, IRQ, RS232 addr  *)
  77. (*     Async_Stuff            ---    Insert char into receive buffer    *)
  78. (*     Async_Flush_Output_Buffer                                        *)
  79. (*                            ---    Flush serial port output buffer    *)
  80. (*     Async_Drain_Output_Buffer                                        *)
  81. (*                            ---    Wait for serial output to drain    *)
  82. (*     Async_Port_Address_Given                                         *)
  83. (*                            ---    Check if port address installed    *)
  84. (*     Async_Send_Now         ---    Send character without buffering   *)
  85. (*     Async_Wait_For_Quiet   ---    Wait for port to quiesce           *)
  86. (*                                                                      *)
  87. (*----------------------------------------------------------------------*)
  88. (*                                                                      *)
  89. (*      PIBASYNC.PAS was split into PIBASYN1.PAS and PIBASYN2.PAS at    *)
  90. (*      version 3.2 of PibTerm, and into PIBASYN1, PIBASYN2, and        *)
  91. (*      PIBASYN3 for v4.0 of PibTerm.   The UNIT structure was added    *)
  92. (*      for use with Turbo Pascal v4.0.                                 *)
  93. (*                                                                      *)
  94. (*----------------------------------------------------------------------*)
  95.  
  96. INTERFACE
  97.                                    (* Uncomment PibMTask if the    *)
  98.                                    (* multitasking interface is to *)
  99.                                    (* be used.                     *)
  100. USES
  101.    Dos, Crt, GlobType, PibTimer{, PibMTask};
  102.  
  103. (*$I PIBASYNC.GLO *)
  104.  
  105. PROCEDURE BIOS_RS232_Init( ComPort : INTEGER; ComParm : WORD );
  106. PROCEDURE Async_Close( Drop_DTR: BOOLEAN );
  107. PROCEDURE Async_Clear_Errors;
  108. PROCEDURE Async_Reset_Port( ComPort       : INTEGER;
  109.                             BaudRate      : WORD;
  110.                             Parity        : CHAR;
  111.                             WordSize      : INTEGER;
  112.                             StopBits      : INTEGER  );
  113. FUNCTION  Async_Open( ComPort       : INTEGER;
  114.                       BaudRate      : WORD;
  115.                       Parity        : CHAR;
  116.                       WordSize      : INTEGER;
  117.                       StopBits      : INTEGER  ) : BOOLEAN;
  118. PROCEDURE Async_Send( C : Char );
  119. FUNCTION Async_Receive( VAR C : Char ) : BOOLEAN;
  120. PROCEDURE Async_Receive_With_Timeout( Secs : INTEGER; VAR C : INTEGER );
  121. PROCEDURE Async_Stuff( Ch: CHAR );
  122. PROCEDURE Async_Find_Delay( VAR One_MS_Delay : INTEGER );
  123. PROCEDURE Async_Init( Async_Buffer_Max  : INTEGER;
  124.                       Async_OBuffer_Max : INTEGER;
  125.                       Async_High_Lev1   : INTEGER;
  126.                       Async_High_Lev2   : INTEGER;
  127.                       Async_Low_Lev     : INTEGER );
  128. FUNCTION  Async_Carrier_Detect : BOOLEAN;
  129. FUNCTION  Async_Carrier_Drop : BOOLEAN;
  130. PROCEDURE Async_Term_Ready( Ready_Status : BOOLEAN );
  131. FUNCTION  Async_Buffer_Check : BOOLEAN;
  132. FUNCTION  Async_Line_Error( VAR Error_Flags: BYTE ) : BOOLEAN;
  133. FUNCTION  Async_Ring_Detect : BOOLEAN;
  134. PROCEDURE Async_Send_Break;
  135. PROCEDURE Async_Send_String( S : AnyStr );
  136. PROCEDURE Async_Send_String_With_Delays( S          : AnyStr;
  137.                                          Char_Delay : INTEGER;
  138.                                          EOS_Delay  : INTEGER  );
  139. FUNCTION  Async_Percentage_Used : REAL;
  140. PROCEDURE Async_Purge_Buffer;
  141. FUNCTION  Async_Peek( Nchars : INTEGER ) : CHAR;
  142. PROCEDURE Async_Setup_Port( ComPort       : INTEGER;
  143.                             Base_Address  : INTEGER;
  144.                             IRQ_Line      : INTEGER;
  145.                             Int_Numb      : INTEGER );
  146. PROCEDURE Async_Release_Buffers;
  147. PROCEDURE Async_Flush_Output_Buffer;
  148. PROCEDURE Async_Drain_Output_Buffer( Max_Wait_Time : INTEGER );
  149. FUNCTION  Async_Port_Address_Given( Com_Port : INTEGER ) : BOOLEAN;
  150. PROCEDURE Async_Send_Now( C : Char );
  151. FUNCTION  Async_Wait_For_Quiet( Max_Wait : LONGINT;
  152.                                 Wait_Time: LONGINT  ) : BOOLEAN;
  153. PROCEDURE Async_Set_Rejection( Reject_Bad : BOOLEAN; Reject_Char : CHAR );
  154.  
  155. IMPLEMENTATION
  156.                                    (* Remove blank before $ in next *)
  157.                                    (* statement to get multitasking *)
  158.                                    (* defined.                      *)
  159. { $DEFINE MTASK }
  160.  
  161. (*$I PIBASYN1.MOD *)
  162. (*$I PIBASYN2.MOD *)
  163. (*$I PIBASYN3.MOD *)
  164.  
  165. BEGIN (* PibAsync *)
  166.                                    (* Default communications parameters *)
  167.    Async_Do_CTS         := FALSE;
  168.    Async_Do_DSR         := FALSE;
  169.    Async_Hard_Wired_On  := FALSE;
  170.    Async_Break_Length   := 500;
  171.    Async_Do_XonXoff     := TRUE;
  172.    Async_OV_XonXoff     := TRUE;
  173.    Async_Buffer_Length  := 4096;
  174.    Async_OBuffer_Length := 1132;
  175.    Async_Reject_Noise   := FALSE;
  176.    Async_Noise_Char     := CHR( 0 );
  177.  
  178.                                    (* Port addresses of each com port *)
  179.  
  180.    Default_Com_Base[1]  := COM1_Base;
  181.    Default_Com_Base[2]  := COM2_Base;
  182.    Default_Com_Base[3]  := COM3_Base;
  183.    Default_Com_Base[4]  := COM4_Base;
  184.  
  185.                                    (* IRQ line for each port *)
  186.  
  187.    Default_Com_Irq [1]  := COM1_Irq;
  188.    Default_Com_Irq [2]  := COM2_Irq;
  189.    Default_Com_Irq [3]  := COM3_Irq;
  190.    Default_Com_Irq [4]  := COM4_Irq;
  191.  
  192.                                    (* Pick up address of send-a-character *)
  193.                                    (* routine, which is used by INLINE    *)
  194.                                    (* code.                               *)
  195.  
  196.    Async_Send_Addr := ADDR( Async_Send );
  197.  
  198. END   (* PibAsync *).
  199.